# include <bits/stdc++.h>
# define MAXM 1024
using namespace std;
inline char getc() { 
    static char buf[1 << 18], *fs, * ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}
inline int gn() { 
    register int k = 0, f = 1;
    register char c = getc();
    for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
    for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
    return f * k;
}

struct times { 
    int l, r, e;
    bool operator <(const times &x) const { 
        return l < x.l;
    }
}t[MAXM];

int n, m, r, dp[MAXM];

int main() { 
    freopen("milkprod.in", "r", stdin);
    freopen("milkprod.out", "w", stdout);
    n = gn(), m = gn(), r = gn();
    for(int i = 1; i <= m; i++) { 
        times *b = &t[i];
        b->l = gn(), b->r = gn(), b->e = gn();
    }
    sort(t + 1, t + 1 + m);
    int ans = 0;
    for(int i = 1; i <= m; i++) { 
        dp[i] = t[i].e;
        for(int j = 1; j < i; j++) { 
            if(t[j].r + r <= t[i].l) { 
                dp[i] = max(dp[i], dp[j] + t[i].e);
                ans = max(dp[i], ans);
            }
        }
    }
    printf("%d\n", ans);
}
